﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OF.Component.Base;
using OF.Component.BLL;
using OF.Component.Model;
using OF.Utility;

namespace OP.manage.ajax
{
    public partial class ajaxLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            switch (Request["action"])
            {
                case "Login":
                    Login();
                    break;
               
                default:
                    break;
            }
        }

        public void Login()
        {
            string szReturn = AjaxResult.Error("未知错误").ToString();
            string strUserName = RequestUtility.GetString("UserName");
            string strPassWord = RequestUtility.GetString("Password");
            string validateCode = RequestUtility.GetString("ValidateCode");
            if (Session["CheckCode"] != null)
            {
                if (Session["CheckCode"].ToString().ToUpper() != validateCode.ToUpper())
                {
                    szReturn = AjaxResult.Error("验证码不正确请重新输入").ToString();
                }
                else
                {
                    OpUserInforInfo info = OpUserInforOperate.GetByLoginName(strUserName);
                    if (info != null)
                    {
                        var enPwd = SecurityUtility.EncryptAsc(strPassWord);
                        if (info.PassWord == enPwd)
                        {
                            OpUserInforManager.Login(info.OpUserID);
                            string loginUrl = string.Format(SiteUtility.GetBaseURL() + "/default.aspx");
                            szReturn = AjaxResult.Success(loginUrl, "登录成功").ToString();
                        }
                        else
                        {
                            szReturn = AjaxResult.Error("用户名或密码不正确请重新输入！").ToString();
                        }
                    }
                    else
                    {
                        szReturn = AjaxResult.Error("用户名或密码不正确请重新输入！").ToString();
                    }
                }
                Response.Write(szReturn);
            }
            
        }
    


    }
}